package decisiontest;

import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.ZonedDateTime;

public class Bill {
    private static final int LIMIT_H = 30;
    private static final double MINT = 60.0;
    private static final double INITIAL_CHARGE_RATE = 0.05;
    private static final double ADDITIONAL_CHARGE_RATE = 0.10;
    private static final double MINUTE_THRESHOLD = 20.0;
    private static final double MILLS = 1000.0;
    private static final double MINUTE_CHARGE = 1.0;
    public long calculateTime(final LocalDateTime startTime, final LocalDateTime endTime) {
        ZoneId zone = ZoneId.of("America/New_York");
        ZonedDateTime callStartZoned = startTime.atZone(zone);
        ZonedDateTime callEndZoned = endTime.atZone(zone);
//        boolean startIsDST = zone.getRules().isDaylightSavings(callStartZoned.toInstant());
//        boolean endIsDST = zone.getRules().isDaylightSavings(callEndZoned.toInstant());
//        if (startIsDST && !endIsDST) {
//            callEndZoned = callEndZoned.plusHours(1);
//        } else if(!startIsDST && endIsDST) {
//            callEndZoned = callEndZoned.minusHours(1);
//        }
        // 计算时间差
        java.time.Duration duration = java.time.Duration.between(callStartZoned, callEndZoned);

        long timeLength = (long) Math.ceil(duration.toMillis() / MILLS / MINT);  // 向上取整分钟数
        if (timeLength > LIMIT_H * MINT) {  // 超过30h
            return 0;
        }
        return timeLength;
    }
    public double calculateFee(final long timeLength) {
        double cost = 0;
        if (timeLength <= 0) {
            cost = -MINUTE_CHARGE;
        } else if (timeLength <= MINUTE_THRESHOLD) {  // <20min
            cost = timeLength * INITIAL_CHARGE_RATE;
        } else {
            cost = MINUTE_CHARGE + (timeLength - MINUTE_THRESHOLD) * ADDITIONAL_CHARGE_RATE;
        }

        return cost;
    }
}
